﻿using System.Collections.Generic;
using System.Data;
using MaLu.Data;
using System;

namespace MaLu.BusiLogic
{
    public class BLCommon
    {
        public static DataTable GetPagingList(IDbProvider provider, string Fields, string Table, string Where, string Order, int PageIndex, int PageSize, bool UseDistinct, int Action, ref int TotalCount)
       {
           List<IDataParameter> paraList = new List<IDataParameter>();
           paraList.Add(SqlHelper.Instance.CreateParameter("@Fields", DataType.VarChar,200,Fields));
           paraList.Add(SqlHelper.Instance.CreateParameter("@Table", DataType.VarChar, 200, Table));
           paraList.Add(SqlHelper.Instance.CreateParameter("@Where", DataType.VarChar, 4000, Where));
           paraList.Add(SqlHelper.Instance.CreateParameter("@Order", DataType.VarChar, 50, Order));
           paraList.Add(SqlHelper.Instance.CreateParameter("@PageIndex", DataType.Int32, 8, PageIndex));
           paraList.Add(SqlHelper.Instance.CreateParameter("@PageSize", DataType.Int32, 8, PageSize));
           paraList.Add(SqlHelper.Instance.CreateParameter("@UseDistinct", DataType.Bit, 1, UseDistinct));
           paraList.Add(SqlHelper.Instance.CreateParameter("@Action", DataType.Int32, 8, Action));
           paraList.Add(SqlHelper.Instance.CreateParameter("@TotalCount", DataType.Int32, ParameterDirection.Output));
           
           DataSet ds = SqlHelper.Instance.ExecuteProcedure(provider, "Proc_PagingCanDistinct", paraList.ToArray());

           int.TryParse(ds.Tables[1].Rows[0][0].ToString(), out TotalCount);
           return ds.Tables[0];
       }
      
    } 
}
